VB Sample Code for modifying Subreports

Private Sub mnuFileSubReportOpen_Click()
Dim result%, jobnum%, sectionN%, sectionCode%, subreportN%, subreportHandle&
Dim x As Integer, y As Integer
Dim subreportInfo As PESubreportInfo

result% = PEOpenEngine()
If result% = 0 Then
MsgBox "Could not start the report engine. Execution must halt.", vbOKOnly + vbCritical, "Serious Error"
End
End If

jobnum% = PEOpenPrintJob(lblReportName.Caption) ' Name from label on sample form
ErrorTrap "OpenPrintJob in FileSubReportOpen", jobnum%

' Define the size of the SubReportInfo structure
subreportInfo.StructSize = PE_SIZEOF_SUBREPORT_INFO

' Load the Sections form for displaying the selection of subreports available
Load Sections
CenterForm Sample, Sections
Sections.Caption = "Open Subreport"
Sections!cmdEdit.Caption = "&Cancel"

' Find number of sections and loop through each section checking for the existence of subreports
sectionN% = PEGetNSections(jobnum%)
ErrorTrap "GetNSections in FileSubReportOpen", jobnum%
For x = 0 To sectionN% - 1
' Get section code
sectionCode% = PEGetSectionCode(jobnum%, x)
ErrorTrap "GetSectionCode in FileSubReportOpen", jobnum%
' Get number of subreports in section
subreportN% = PEGetNSubreportsInSection(jobnum%, sectionCode%)
ErrorTrap "GetNSubreportsInSection in FileSubReportOpen", jobnum%
' If there are subreports, get the handle and name for adding to list
If result% > 0 Then
For y = 0 To subreportN% - 1
' Get handle for subreport
subreportHandle& = PEGetNthSubreportInSection(jobnum%, sectionCode%, y)
ErrorTrap "GetNthSubreportInSection in FileSubReportOpen", jobnum%
' Get info for subreport
result% = PEGetSubreportInfo(jobnum%, subreportHandle&, subreportInfo)
ErrorTrap "GetSubReportInfo in FileSubReportOpen", jobnum%
' Load info into section form list box
Sections!lstSections.AddItem subreportInfo.Name
Next y
End If
Next x

' If the list box on the sections form is still empty, there are no subreports in the report
If Sections!lstSections.ListCount = 0 Then
MsgBox "There are no subreports in this report. Execution must halt.", vbOKOnly + vbCritical, "No subreports!"
Else
' Otherwise, show the Sections form 1 ' Modally to allow selection of a subreport
Sections.Show 1 ' Modal
Select Case Sections.Tag
Case "Ok"
' When a subreport is selected, the main sample form shows the subreport name below the report name
lblSubreportName.Caption = Sections!lstSections.List(Sections!lstSections.ListIndex)
lblSubreportName.Visible = True
lblSubReportLabel.Visible = True
picReportHeader.Height = 855
Case "Edit"
' The edit button caption was changed to Cancel for this case - pressing it cancels selection of a subreport
MsgBox "Cancel pressed. No subreport will be opened.", vbOKOnly + vbCritical, "Cancel pressed"
End Select
End If

Unload Sections

' Close print job and engine
PEClosePrintJob jobnum%

PECloseEngine

End Sub
Related topics:

Working with subreports



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com